<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

class CreateCategoriesTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('categories', function (Blueprint $table) {
            $table->bigIncrements('id')->unsigned();
            $table->unsignedBigInteger('parent_id')->nullable()->comment('父级分类ID')->index();
            $table->string('name', 100)->comment('分类名称');
            $table->string('slug', 100)->comment('分类标识')->unique();
            $table->text('description')->nullable()->comment('分类描述');
            $table->string('icon', 100)->nullable()->comment('分类图标');
            $table->integer('order')->default(0)->comment('排序')->index();
            $table->unsignedInteger('article_count')->default(0)->comment('文章数量');
            $table->timestamps();

            $table->foreign('parent_id')->references('id')->on('categories')->onDelete('set null');

            $table->comment('文章分类表');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('categories');
    }
}
